package com.qj.yantaishan.vo;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qj.yantaishan.common.annotation.Excel;
import com.qj.yantaishan.common.annotation.Where;
import com.qj.yantaishan.common.enums.WhereEnum;
import com.qj.yantaishan.common.utils.StringUtils;
import com.qj.yantaishan.domain.OrderPackage;
import lombok.Data;
import org.phprpc.util.PHPSerializer;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
@TableName("shanglala_order")
public class OrderVo implements Serializable {

    /**
     * 订单id
     */
    @Where(field = "order_id", whereEnum = WhereEnum.LIKE)
    @TableId(type = IdType.AUTO)
    private Integer orderId;

    /**
     * 店铺id
     */
    @Excel(name = "店铺id")
    @Where(field = "store_id", whereEnum = WhereEnum.LIKE)
    private Integer storeId;

    /**
     * 商品的个数
     */
    @Excel(name = "商品的个数")
    private Long proCount;

    /**
     * 商品数量
     */
    @Excel(name = "商品数量")
    private Integer proNum;

    /**
     * 收货地址
     */
    @Excel(name = "收货地址")
    private String address;
    /**
     * 收货人
     */
    @Where(field = "address_user", whereEnum = WhereEnum.LIKE)
    @Excel(name = "收货人")
    private String addressUser;

    /**
     * 收货人电话
     */
    @Excel(name = "收货人电话")
    @Where(field = "address_tel", whereEnum = WhereEnum.LIKE)
    private String addressTel;

    /**
     * 商品金额（不含邮费）
     */
    @Excel(name = "商品金额", readConverterExp = "不=含邮费")
    private BigDecimal subTotal;

    /**
     * 支付方式   codpay==货到付款
     */
    @Excel(name = "支付方式")
    private String paymentMethod;


    /**
     * 订单金额（含邮费）
     */
    @Excel(name = "订单金额", readConverterExp = "含=邮费")
    private BigDecimal total;

    /**
     * 邮费
     */
    @Excel(name = "邮费")
    private BigDecimal postage;


    /**
     * 订单浮动金额
     */
    @Excel(name = "订单浮动金额")
    private BigDecimal floatAmount;
    /**
     * 买家id
     */
    @Excel(name = "买家id")
    private Long uid;
    /**
     * 交易号
     */

    @Where(field = "trade_no", whereEnum = WhereEnum.LIKE)
    @Excel(name = "交易号")
    private String tradeNo;


    @TableField(exist = false)
    private String serializeAddr;

    public String getAddress() {
        return address;
    }

    public String getSerializeAddr() {
        return serializeAddr;
    }

    public void setSerializeAddr(String serializeAddr) {
        PHPSerializer ps = new PHPSerializer();
        AddressVo json = null;
        if (StringUtils.isNotEmpty(this.address)) {
            try {
                json = (AddressVo) ps.unserialize(this.address.getBytes(),
                        AddressVo.class);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
            this.serializeAddr = JSON.toJSONString(json);
        }


    }

    public void setAddress(String address) {
        this.address = address;
        PHPSerializer ps = new PHPSerializer();
        AddressVo json = null;
        try {
            json = (AddressVo) ps.unserialize(this.address.getBytes(), AddressVo.class);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        this.serializeAddr = JSON.toJSONString(json);
    }

    /**
     * 订单号
     */
    @Where(field = "order_no", whereEnum = WhereEnum.LIKE)
    @Excel(name = "订单号")
    private String orderNo;

    /**
     * 供货商id
     */
    @Excel(name = "供货商id")
    private Integer rootSupplierId;
    /**
     * 订单状态 0临时订单 1未支付 2未发货 3已发货 4已完成 5已取消 6退款中
     */
    @Excel(name = "订单状态 0临时订单 1未支付 2未发货 3已发货 4已完成 5已取消 6退款中 ")
    private Integer status;
    /**
     * 订单时间
     */
    @Excel(name = "订单时间")
    private Long addTime;

    /**
     * 付款时间
     */
    @Excel(name = "付款时间")
    private Long paidTime;

    /**
     * 发货时间
     */
    @Excel(name = "发货时间")
    private Long sentTime;

    /**
     * 收货时间
     */
    @Excel(name = "收货时间")
    private Long deliveryTime;

    /**
     * 货到付款时，收款时间
     */
    @Excel(name = "货到付款时，收款时间")
    private Long receiveTime;
    /**
     * 取消时间
     */
    @Excel(name = "取消时间")
    private Long cancelTime;

    /**
     * 完成时间
     */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private Long complateTime;
    /**
     * 退款时间
     */
    @Excel(name = "退款时间")
    private Long refundTime;
    /**
     * 买家留言
     */
    @Excel(name = "买家留言")
    private String comment;
    /**
     * 卖家留言
     */
    @Excel(name = "卖家留言")
    private String bak;
    /**
     * 物流方式 express快递发货 selffetch上门自提 self_choice自选物流
     */
    @Where(field = "shipping_method", whereEnum = WhereEnum.LIKE)
    @Excel(name = "物流方式 express快递发货 selffetch上门自提 self_choice自选物流")
    private String shippingMethod;
    /**
     * 加星订单 1|2|3|4|5 默认0
     */
    @Excel(name = "加星订单 1|2|3|4|5 默认0")
    private Integer star;
    /**
     * 实际付款金额
     */
    @Excel(name = "实际付款金额")
    private BigDecimal payMoney;
    /**
     * 订单取消方式 0过期自动取消 1卖家手动取消 2买家手动取消
     */
    @Excel(name = "订单取消方式 0过期自动取消 1卖家手动取消 2买家手动取消")
    private Integer cancelMethod;


    /**
     * 收款店铺id
     */
    @Excel(name = "收款店铺id")
    @TableField("storePay")
    private Long storePay;
    /**
     * 订单待付款到期时间
     */
    @Excel(name = "订单待付款到期时间")
    private Long orderPaidExpire;
    /**
     * 订单来源平台 0 h5, 1 app, 2 小程序, 3 收银台
     */
    @Excel(name = "订单来源平台 0 h5, 1 app, 2 小程序, 3 收银台")
    @Where(field = "source_platform", whereEnum = WhereEnum.EQ)
    private Integer sourcePlatform;
    @Excel(name = "对接活动类型")
    @Where(field = "activity_type", whereEnum = WhereEnum.EQ)
    private String activityType;
    /**
     * 发货/自提操作人
     */
    @Excel(name = "发货/自提操作人")
    private Integer operaterId;
    @TableField(exist = false)
    List<OrderProductVo> orderProductVos;
    @TableField(exist = false)
    OrderPackage orderPackage;
    /**
     * 订单类型 0普通 1代付 2送礼 3分销
     */
    @Excel(name = "订单类型 0普通 1代付 2送礼 3分销")
    @Where(field = "type", whereEnum = WhereEnum.EQ)
    private Integer type;


    @TableField(exist = false)
    private List<Map<String, Object>> returnProductList;

}
